home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / uwpc201.zip / UW-SRC.ZIP / FILES.H < prev    next >
C/C++ Source or Header  |  1991-05-25  |  5KB  |  164 lines

  1. //-------------------------------------------------------------------------
  2. //
  3. // FILES.H - Declarations for creating UW clients for file transfers.
  4. // 
  5. // NOTE: <stdio.h> must be included before this file.
  6. //
  7. //  This file is part of UW/PC - a multi-window comms package for the PC.
  8. //  Copyright (C) 1990-1991  Rhys Weatherley
  9. //
  10. //  This program is free software; you can redistribute it and/or modify
  11. //  it under the terms of the GNU General Public License as published by
  12. //  the Free Software Foundation; either version 1, or (at your option)
  13. //  any later version.
  14. //
  15. //  This program is distributed in the hope that it will be useful,
  16. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. //  GNU General Public License for more details.
  19. //
  20. //  You should have received a copy of the GNU General Public License
  21. //  along with this program; if not, write to the Free Software
  22. //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. //
  24. // Revision History:
  25. // ================
  26. //
  27. //  Version  DD/MM/YY  By  Description
  28. //  -------  --------  --  --------------------------------------
  29. //    1.0    11/04/91  RW  Original Version of FILES.H
  30. //    1.1    11/05/91  RW  Added X/YMODEM file transfers.
  31. //
  32. // You may contact the author by:
  33. // =============================
  34. //
  35. //  e-mail: rhys@cs.uq.oz.au
  36. //    mail: Rhys Weatherley
  37. //          5 Horizon Drive
  38. //          Jamboree Heights
  39. //          Queensland 4074
  40. //        Australia
  41. //
  42. //-------------------------------------------------------------------------
  43.  
  44. #ifndef __FILES_H__
  45. #define    __FILES_H__
  46.  
  47. #include "client.h"        // Client processing declarations.
  48.  
  49. //
  50. // Define the structure of a UW file transfer client.
  51. //
  52. class    UWFileTransfer : public UWClient {
  53.  
  54. protected:
  55.  
  56.     FILE    *file;            // Current file being processed.
  57.  
  58. public:
  59.  
  60.     UWFileTransfer (UWDisplay *wind) : UWClient (wind) {};
  61.  
  62.     virtual    char far *name    () { if (underneath)
  63.                        return (underneath -> name ());
  64.                       else
  65.                        return ((char far *)"FILES");
  66.                    };
  67.  
  68. };
  69.  
  70. //
  71. // Define the structure of a file transfer client for performing
  72. // ASCII file transfers to the remote host.  Transfers are of
  73. // three kinds: ASCII upload, ASCII download and screen capture.
  74. // Screen capture exists to allow a normal terminal session to
  75. // continue, yet also to place received characters into a file.
  76. //
  77. #define    ASCII_UPLOAD    0
  78. #define    ASCII_DOWNLOAD    1
  79. #define ASCII_CAPTURE    2
  80. //
  81. class    UWAsciiFileTransfer : public UWFileTransfer {
  82.  
  83. protected:
  84.  
  85.     int    kind;            // Kind of ASCII file transfer.
  86.  
  87. public:
  88.  
  89.     UWAsciiFileTransfer (UWDisplay *wind,int type,char *name);
  90.     ~UWAsciiFileTransfer (void);
  91.  
  92.     virtual    char far *name    () { if (kind == ASCII_CAPTURE)
  93.                        return ((char far *)" CAP");
  94.                       else if (kind == ASCII_UPLOAD)
  95.                        return ((char far *)"UP-LD");
  96.                       else
  97.                        return ((char far *)"DN-LD");
  98.                    };
  99.  
  100.     virtual    void    key    (int keypress);
  101.     virtual    void    remote    (int ch);
  102.     virtual    void    tick    (void);
  103.     virtual    char    *getstatus (void);
  104. };
  105.  
  106. //
  107. // Define the structure of a X/YMODEM file transfer protocol
  108. // Because of the nature of clients these protocols must be
  109. // written as state machines.
  110. //
  111. #define    XMOD_ORIGINAL    0    // Original XMODEM protocol.
  112. #define    XMOD_CRC    1    // XMODEM with CRC-16.
  113. #define    XMOD_1K        2    // XMODEM with 1K blocks.
  114. #define    XMOD_1K_CRC    3    // XMODEM with 1K blocks and CRC-16.
  115. #define    YMOD_NORMAL    4    // Normal YMODEM protocol.
  116. #define    YMOD_BATCH    5    // YMODEM protocol with batch.
  117. #define    YMOD_G        6    // YMODEM G protocol (fast/unreliable).
  118. //
  119. class    UWXYFileTransfer : public UWFileTransfer {
  120.  
  121. protected:
  122.  
  123.     int    state;        // Current transfer state.
  124.     int    kind;        // Kind of transfer that is in effect.
  125.     int    receive;    // Non-zero for a receive.
  126.     int    timer;        // For keeping track of timers.
  127.     int    timeout;    // Length of timeout (-1 if none).
  128.     int    bigblock;    // Non-zero for a 1K block receive.
  129.     char    buffer[1024];    // Buffer for the data.
  130.     int    posn;        // Current buffer position.
  131.     int    crcblocks;    // Non-zero for CRC blocks.
  132.     int    blocknum;    // Next/expected block number.
  133.     int    thisblock;    // Number of currently received block.
  134.     int    chksum;        // Checksum value.
  135.     int    start;        // Start of transmission.
  136.     int    endfile;    // The end of the file has been reached.
  137.  
  138.     // Do some processing for the current state.  If
  139.     // "ch" is -1, then a timeout has occurred.
  140.     void    process    (int ch);
  141.  
  142.     // Cancel a transmission - a CAN character was received.
  143.     void    cancel    (void);
  144.  
  145.     // Read a block from the file to be sent.  Returns
  146.     // non-zero if OK, or zero at the end of the file.
  147.     int    readblock (void);
  148.  
  149. public:
  150.  
  151.     UWXYFileTransfer (UWDisplay *wind,int type,int recv,char *name);
  152.     ~UWXYFileTransfer (void);
  153.  
  154.     virtual    char far *name    ();
  155.     virtual    void    key    (int keypress);
  156.     virtual    void    remote    (int ch) { process (ch); };
  157.     virtual    void    tick    (void);
  158.     virtual    char    *getstatus (void);
  159.     virtual    int    getstatarg (int digit);
  160.  
  161. };
  162.  
  163. #endif    /* __FILES_H__ */
  164.